package com.ljcalc.business.components;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;

public class CombinationsSet extends LinkedList<Combination> {
	
	//key is the content of the combinations
	//value is the position of the combination
	HashMap<String, Long> combContentControlMap; 
	
	public CombinationsSet(long size, int historytype){
		for(long i=0;i<size;i++){
			this.add(ResultHistory.generateCombination(historytype));
		}
		
		combContentControlMap = new HashMap<String, Long>();
	}
	
	/**
	 * clear out the identical contents
	 * @return true if there is no identical, false if there is identical removed
	 */
	public boolean organize(){
		
		boolean ret = true;
		combContentControlMap.clear();
		long i = 0;
		Iterator<Combination> itr = this.iterator();
		while (itr.hasNext()) {
			Combination comb = itr.next();
			String key = comb.toString();
			if(combContentControlMap.get(key)==null){
				combContentControlMap.put(comb.toString(), new Long(i++));
			}else{
				itr.remove();
				ret = false;
			}
		}
		
		return ret;

	}

}
